﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

using Ah.Testudin.Engine.Actors;

namespace Ah.Testudin.Engine.Graphics.Scenes.SceneNodes
{
    public class RootSceneNode : SceneNodeBase
    {
        #region Private Member Variables

        private ISceneNode _staticActorsRootNode;

        private ISceneNode _dynamicActorsRootNode;

        #endregion

        #region Constructors

        public RootSceneNode()
            : base("Root", null, RenderPass.StaticActor, Matrix.Identity)
        {
            _staticActorsRootNode = new TopLevelSceneNode(
                "Static Actors Root Node",
                RenderPass.StaticActor,
                Matrix.Identity);

            _dynamicActorsRootNode = new TopLevelSceneNode(
                "Static Actors Root Node",
                RenderPass.DynamicActor,
                Matrix.Identity);
        }

        #endregion

        #region SceneNodeBase

        public override void AddChildNode(ISceneNode childNode)
        {
            RenderPass renderPass = childNode.Properties.RenderPass;

            switch (renderPass)
            {
                case RenderPass.StaticActor:

                    _staticActorsRootNode.AddChildNode(childNode);

                    break;

                case RenderPass.DynamicActor:

                    _dynamicActorsRootNode.AddChildNode(childNode);

                    break;

                default:

                    throw new Exception("Unrecognized render pass");
            }
        }

        public override void RemoveChildNode(ISceneNode sceneNode)
        {
            RenderPass renderPass = sceneNode.Properties.RenderPass;

            switch (renderPass)
            {
                case RenderPass.StaticActor:

                    _staticActorsRootNode.RemoveChildNode(sceneNode);

                    break;

                case RenderPass.DynamicActor:

                    _dynamicActorsRootNode.RemoveChildNode(sceneNode);

                    break;

                default:

                    throw new Exception("Unrecognized render pass");
            }
        }

        public override void Render(Scene scene)
        {
            // I don't draw anything
        }

        public override void RenderChildren(Scene scene)
        {
            _staticActorsRootNode.RenderChildren(scene);

            _dynamicActorsRootNode.RenderChildren(scene);
        }

        #endregion
    }
}
